import axios from "axios";
import store from "store";

export const routesTree = [
  {
    path: '/layouts/welcome',
    component: 'dashboard/Welcome.vue',
    meta: {
      title: '驾驶舱',
      icon: 'PieChartOutlined'
    }
  },
  {
    path: '/layouts/users',
    meta: {
      title: '用户管理',
      icon: 'PieChartOutlined',
      permissions: ['admin']
    },
    redirect: '/layouts/users/list',
    children: [
      {
        path: '/layouts/users/list',
        component: 'users/UserList.vue',
        meta: {
          title: '用户列表',
          icon: 'PieChartOutlined'
        }
      },
      {
        path: '/layouts/users/edit',
        component: 'users/UserEdit.vue',
        meta: {
          title: '用户管理',
          icon: 'MenuUnfoldOutlined'
        }
      }
    ]
  },
  {
    path: '/layouts/products',
    meta: {
      title: '产品管理',
      icon: 'PayCircleOutlined',
      permissions: ['admin', 'users']
    },
    redirect: '/layouts/products/list',
    children: [
      {
        path: '/layouts/products/list',
        component: 'products/ProList.vue',
        meta: {
          title: '产品列表',
          icon: 'MenuFoldOutlined'
        }
      },
      {
        path: '/layouts/products/new',
        component: 'products/ProNew.vue',
        meta: {
          title: '最新上架',
          icon: 'MehOutlined'
        }
      }
    ]
  },
  {
    path: '/layouts/banner',
    meta: {
      title: '轮播图管理',
      icon: 'PayCircleOutlined',
      permissions: ['admin', 'users']
    },
    component: 'banner/Banner.vue'
  },
  {
    path: '/layouts/table',
    meta: {
      title: '表格管理',
      icon: 'PayCircleOutlined',
      permissions: ['admin', 'users']
    },
    redirect: '/layouts/table/table1',
    children: [
      {
        path: '/layouts/table/table1',
        meta: {
          title: '表格合并DEMO',
          icon: 'PayCircleOutlined',
          permissions: ['admin', 'users']
        },
        component: 'table/TableDemo.vue'
      },
      {
        path: '/layouts/table/table2',
        meta: {
          title: '通用表格合并',
          icon: 'PayCircleOutlined',
          permissions: ['admin', 'users']
        },
        component: 'table/Table.vue'
      }
    ]
  },
  {
    path: '/layouts/filter-table',
    meta: {
      title: '查询表格',
      icon: 'PayCircleOutlined',
      permissions: ['admin', 'users']
    },
    component: 'table/FilterTable.vue'
  }
]

async function fetchRouteTree() {
  //请求接口
  const result = await axios({
    url: '/api/syspermission/menuvue3',
    method: 'get',
    headers:{
      access_token: store.get('access_token')
    }
  })
  //接口的结果数据验证
  if(result.data.code==0){
    return  result.data.data;
  }else {
    return routesTree;
  }
}
export default fetchRouteTree
